{extend name="base"}
{block name="main"}
<h3>添加商品</h3>
<form action="{:url('admin/goods/edit')}?id={$id}" method="post" enctype="multipart/form-data">
<table width="70%"  border="1" cellpadding="5" cellspacing="0" bgcolor="#cccccc">
	<tr>
		<td align="right">商品名称</td>
		<td><input type="text" name="gName"  value="{$info.gName}"/></td>
	</tr>
	<tr>
		<td align="right">商品分类</td>
		<td>
		<select name="cId">
			{volist name="cateList" id="cate"}
				<option value="{$cate.id}">{$cate.cName}</option>
			{/volist}
		</select>
		</td>
	</tr>
	<tr>
		<td align="right">商品货号</td>
		<td><input type="text" name="gSn"  value="{$info.gSn}"/></td>
	</tr>
	<tr>
		<td align="right">商品数量</td>
		<td><input type="text" name="gNum"  value="{$info.gNum}"/></td>
	</tr>
	<tr>
		<td align="right">商品市场价</td>
		<td><input type="text" name="mPrice"  value="{$info.mPrice}"/></td>
	</tr>
	<tr>
		<td align="right">商品慕课价</td>
		<td><input type="text" name="iPrice"  value="{$info.iPrice}"/></td>
	</tr>
	<tr>
		<td align="right">商品描述</td>
		<td>
			<textarea name="gDesc" id="editor_id" style="width:100%;height:150px;">{$info.gDesc}</textarea>
		</td>
	</tr>
	<tr>
        <td colspan="2"><button id="submit" type="button" class="submit">编辑商品</button></td>
	</tr>
</table>
</form>

{load href='__PUBLIC__/static/js/jquery-3.1.1.min.js'}
{load href='__PUBLIC__/plugins/kindeditor-4.1.7/kindeditor.js'}
{load href='__PUBLIC__/plugins/kindeditor-4.1.7/lang/zh_CN.js'}
<script type="text/javascript">
	KindEditor.ready(function(K) {
        window.editor = K.create('#editor_id');
    });
    $(document).ready(function(){
    	$("#selectFileBtn").click(function(){
    		$fileField = $('<input type="file" name="thumbs[]"/>');
    		$fileField.hide();
    		$("#attachList").append($fileField);
    		$fileField.trigger("click");
    		$fileField.change(function(){
    		$path = $(this).val();
    		$filename = $path.substring($path.lastIndexOf("\\")+1);
    		$attachItem = $('<div class="attachItem"><div class="left">a.gif</div><div class="right"><a href="javascript:void(0)" title="删除附件">删除</a></div></div>');
    		$attachItem.find(".left").html($filename);
    		$("#attachList").append($attachItem);		
    		});
    	});
    	$("#attachList").on('click','a',function(obj,i){
    		$(event.target).parents('.attachItem').prev('input').remove();
    		$(event.target).parents('.attachItem').remove();
    	});
    });
    $('.submit').click(function () {
        $.ajax({
            cache: true,
            type: "POST",
            url : '{:url('admin/goods/edit')}',
            data: $('#editAdmin ').serialize(),
            async: false,
            success: function(data) {
                if (data.code) {
                    alert(data.msg);
                    setTimeout(function () {
                        location.href = data.url;
                    }, 1000);
                } else {
                alert(data.msg);
                }
            },
            error: function(request) {
                alert("页面错误");
            }
        });
    });
</script>
{/block}